<?php
//满 XX 元免费快递插件
//By avenger
//2007-3-22 20:46
//$Id: freeship.php 9 2009-04-26 06:35:12Z bole.Chen $

//定义满 ? 元免费快递
define('FREESHIP_MIN_PRICE', 198);

//定义包含这些产品的订单免运费
$freeship_ids = array();

function freeship_setiid($ids) {
    global $freeship_ids;
    $freeship_ids = array_merge($ids, $freeship_ids);
}

add_action('view_checkout_msg', 'freeship_checkout_msg');
add_action('view_checkout_ship', 'freeship_ckship');
add_action('shopcar_checkout_befor', 'freeship_shopcar_checkout_befor');

function freeship_ckship($shopcar='') {
    global $freeship_ids;

    //产品免运费判断
    $flag = 0;
    foreach ($shopcar['list'] as $v) {
        if (in_array($v['iid'], $freeship_ids)) {
            $flag = 1;
            break;
        }
    }

    if ($shopcar['totalprice'] >= FREESHIP_MIN_PRICE || $flag) {
        $_SESSION['freeship_mark'] = true;
        echo <<< FREESHIP
<div id="freeship" style="margin-bottom:15px;display:none">
<h3><img src="/images/icon_arrow_down.gif" />请选择您需要的送货方式</h3>

<ul style="padding:0;margin-left:20px;list-style-type:none" class="l20">
<li><input onclick="javascript:change_sumprice(0)" id="freeship_f0" type="radio" name="postfee" value="0" checked="checked" /> <label for="freeship_f0" title="免费上门快递"><img src="/images/icon/icon_gift_small.gif" /> <b style="color:red">免费上门快递!</b></label> &nbsp;&nbsp;<small class="px12" style="color:blue">(国内大中城市均可送货上门，最迟一周内到达)</small> </li>
<!--<li><input onclick="javascript:change_sumprice(0)" id="freeship_f0" type="radio" name="postfee" value="0" checked="checked" /> <label for="freeship_f0" title="免费上门快递"><img src="/images/icon/icon_gift_small.gif" /> <b style="color:red">免费上门快递!</b></label> &nbsp;&nbsp;<small class="px12" style="color:blue">(注意：春节期间暂停发货，2月2日[初八]发货)</small> </li>-->
<li><input onclick="javascript:change_sumprice(0)" id="freeship_f1" type="radio" name="postfee" value="0" /> <label for="freeship_f1" title="福州本市上门自提"><b>上门自提</b></label> &nbsp;&nbsp;<small class="px12" style="color:blue">(福州用户可上门提货，来之前请先电话确认)</small> &nbsp; <a class="px12" href="{$_servername}/aboutus#map" target="_blank">地址请参见</a> </li>
</ul>

</div>
<script type="text/javascript">
addDOMLoadEvent(function(){
    change_sumprice(0)
    Element.hide("posttype");
    Element.show('freeship');
    $('freeship_f0').checked=true;
    //Element.hide('voucher_btn');
    //$('voucher_btn_sub').disabled=true;
})
</script>
FREESHIP;
    } else {
        $_SESSION['freeship_mark'] = false;
    }


if (($needprice = FREESHIP_MIN_PRICE-$shopcar['totalprice']) && $needprice <= 100 && $needprice > 0 && $_SESSION['freeship_mark']==false) {
    echo <<< MSG
<script type="text/javascript">
addDOMLoadEvent(function(){
    $('freeship_price').innerHTML = $needprice;
    Effect.Appear('freeship_checkout_msg');
})
</script>
MSG;
    }

}

function freeship_checkout_msg() {
    echo '<div id="freeship_checkout_msg" class="errbox roundNormal" style="display:none;width:90%">&nbsp;&nbsp;&nbsp;您只要再购买 <span id="freeship_price">100</span> 元的物品，就可以享受乐铺免费快递服务哦！</div><br clear="all" />';
}

function freeship_shopcar_checkout_befor($data) {
    if ($_SESSION['freeship_mark'] == true) $data['posttype'] = '免费快递';
}
?>
